﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HiShing.TongDanGuanJia.Migrations
{
    /// <inheritdoc />
    public partial class init : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "TargetNotifiers",
                table: "AbpNotificationSubscriptions",
                type: "nvarchar(1024)",
                maxLength: 1024,
                nullable: true);

            migrationBuilder.CreateTable(
                name: "DeviceDataHistory",
                columns: table => new
                {
                    Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    DeviceId = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Column1 = table.Column<long>(type: "bigint", nullable: false),
                    Column2 = table.Column<long>(type: "bigint", nullable: false),
                    Column3 = table.Column<long>(type: "bigint", nullable: false),
                    Column4 = table.Column<long>(type: "bigint", nullable: false),
                    Column5 = table.Column<long>(type: "bigint", nullable: false),
                    Column6 = table.Column<long>(type: "bigint", nullable: false),
                    Column7 = table.Column<long>(type: "bigint", nullable: false),
                    Column8 = table.Column<long>(type: "bigint", nullable: false),
                    Column9 = table.Column<long>(type: "bigint", nullable: false),
                    Column10 = table.Column<long>(type: "bigint", nullable: false),
                    Column11 = table.Column<long>(type: "bigint", nullable: false),
                    Column12 = table.Column<long>(type: "bigint", nullable: false),
                    Column13 = table.Column<long>(type: "bigint", nullable: false),
                    Column14 = table.Column<long>(type: "bigint", nullable: false),
                    Column15 = table.Column<long>(type: "bigint", nullable: false),
                    Column16 = table.Column<long>(type: "bigint", nullable: false),
                    Column17 = table.Column<long>(type: "bigint", nullable: false),
                    Column18 = table.Column<long>(type: "bigint", nullable: false),
                    Column19 = table.Column<long>(type: "bigint", nullable: false),
                    Column20 = table.Column<long>(type: "bigint", nullable: false),
                    Column21 = table.Column<long>(type: "bigint", nullable: false),
                    Column22 = table.Column<long>(type: "bigint", nullable: false),
                    Column23 = table.Column<long>(type: "bigint", nullable: false),
                    Column24 = table.Column<long>(type: "bigint", nullable: false),
                    Column25 = table.Column<long>(type: "bigint", nullable: false),
                    Column26 = table.Column<long>(type: "bigint", nullable: false),
                    Column27 = table.Column<long>(type: "bigint", nullable: false),
                    Column28 = table.Column<long>(type: "bigint", nullable: false),
                    Column29 = table.Column<long>(type: "bigint", nullable: false),
                    Column30 = table.Column<long>(type: "bigint", nullable: false),
                    Column31 = table.Column<long>(type: "bigint", nullable: false),
                    Column32 = table.Column<long>(type: "bigint", nullable: false),
                    Column33 = table.Column<long>(type: "bigint", nullable: false),
                    Column34 = table.Column<long>(type: "bigint", nullable: false),
                    Column35 = table.Column<long>(type: "bigint", nullable: false),
                    Column36 = table.Column<long>(type: "bigint", nullable: false),
                    Column37 = table.Column<long>(type: "bigint", nullable: false),
                    Column38 = table.Column<long>(type: "bigint", nullable: false),
                    Column39 = table.Column<long>(type: "bigint", nullable: false),
                    Column40 = table.Column<long>(type: "bigint", nullable: false),
                    Column41 = table.Column<long>(type: "bigint", nullable: false),
                    Column42 = table.Column<long>(type: "bigint", nullable: false),
                    Column43 = table.Column<long>(type: "bigint", nullable: false),
                    Column44 = table.Column<long>(type: "bigint", nullable: false),
                    Column45 = table.Column<long>(type: "bigint", nullable: false),
                    Column46 = table.Column<long>(type: "bigint", nullable: false),
                    Column47 = table.Column<long>(type: "bigint", nullable: false),
                    Column48 = table.Column<long>(type: "bigint", nullable: false),
                    Column49 = table.Column<long>(type: "bigint", nullable: false),
                    Column50 = table.Column<long>(type: "bigint", nullable: false),
                    Column51 = table.Column<long>(type: "bigint", nullable: false),
                    Column52 = table.Column<long>(type: "bigint", nullable: false),
                    Column53 = table.Column<long>(type: "bigint", nullable: false),
                    Column54 = table.Column<long>(type: "bigint", nullable: false),
                    Column55 = table.Column<long>(type: "bigint", nullable: false),
                    Column56 = table.Column<long>(type: "bigint", nullable: false),
                    Column57 = table.Column<long>(type: "bigint", nullable: false),
                    Column58 = table.Column<long>(type: "bigint", nullable: false),
                    Column59 = table.Column<long>(type: "bigint", nullable: false),
                    Column60 = table.Column<long>(type: "bigint", nullable: false),
                    Column61 = table.Column<long>(type: "bigint", nullable: false),
                    Column62 = table.Column<long>(type: "bigint", nullable: false),
                    Column63 = table.Column<long>(type: "bigint", nullable: false),
                    Column64 = table.Column<long>(type: "bigint", nullable: false),
                    Column65 = table.Column<long>(type: "bigint", nullable: false),
                    Column66 = table.Column<long>(type: "bigint", nullable: false),
                    Column67 = table.Column<long>(type: "bigint", nullable: false),
                    Column68 = table.Column<long>(type: "bigint", nullable: false),
                    Column69 = table.Column<long>(type: "bigint", nullable: false),
                    Column70 = table.Column<long>(type: "bigint", nullable: false),
                    Column71 = table.Column<long>(type: "bigint", nullable: false),
                    Column72 = table.Column<long>(type: "bigint", nullable: false),
                    Column73 = table.Column<long>(type: "bigint", nullable: false),
                    Column74 = table.Column<long>(type: "bigint", nullable: false),
                    Column75 = table.Column<long>(type: "bigint", nullable: false),
                    Column76 = table.Column<long>(type: "bigint", nullable: false),
                    Column77 = table.Column<long>(type: "bigint", nullable: false),
                    Column78 = table.Column<long>(type: "bigint", nullable: false),
                    Column79 = table.Column<long>(type: "bigint", nullable: false),
                    Column80 = table.Column<long>(type: "bigint", nullable: false),
                    Column81 = table.Column<long>(type: "bigint", nullable: false),
                    Column82 = table.Column<long>(type: "bigint", nullable: false),
                    Column83 = table.Column<long>(type: "bigint", nullable: false),
                    Column84 = table.Column<long>(type: "bigint", nullable: false),
                    Column85 = table.Column<long>(type: "bigint", nullable: false),
                    Column86 = table.Column<long>(type: "bigint", nullable: false),
                    Column87 = table.Column<long>(type: "bigint", nullable: false),
                    Column88 = table.Column<long>(type: "bigint", nullable: false),
                    Column89 = table.Column<long>(type: "bigint", nullable: false),
                    Column90 = table.Column<long>(type: "bigint", nullable: false),
                    Column91 = table.Column<long>(type: "bigint", nullable: false),
                    Column92 = table.Column<long>(type: "bigint", nullable: false),
                    Column93 = table.Column<long>(type: "bigint", nullable: false),
                    Column94 = table.Column<long>(type: "bigint", nullable: false),
                    Column95 = table.Column<long>(type: "bigint", nullable: false),
                    Column96 = table.Column<long>(type: "bigint", nullable: false),
                    Column97 = table.Column<long>(type: "bigint", nullable: false),
                    Column98 = table.Column<long>(type: "bigint", nullable: false),
                    Column99 = table.Column<long>(type: "bigint", nullable: false),
                    Column100 = table.Column<long>(type: "bigint", nullable: false),
                    Column101 = table.Column<long>(type: "bigint", nullable: false),
                    AcquisitionTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DeviceDataHistory", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DeviceMonthDataHistories",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    DeviceId = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    TotalAccount = table.Column<long>(type: "bigint", nullable: false),
                    Month = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DeviceMonthDataHistories", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DeviceType",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false),
                    DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DeviceType", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Device",
                columns: table => new
                {
                    Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    DeviceId = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ProductKey = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    RegisterTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    DeviceTypeId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Device", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Device_DeviceType_DeviceTypeId",
                        column: x => x.DeviceTypeId,
                        principalTable: "DeviceType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "UserDevices",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    UserId = table.Column<long>(type: "bigint", nullable: false),
                    DeviceId = table.Column<string>(type: "nvarchar(450)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserDevices", x => x.Id);
                    table.ForeignKey(
                        name: "FK_UserDevices_AbpUsers_UserId",
                        column: x => x.UserId,
                        principalTable: "AbpUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_UserDevices_Device_DeviceId",
                        column: x => x.DeviceId,
                        principalTable: "Device",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_Device_DeviceTypeId",
                table: "Device",
                column: "DeviceTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_UserDevices_DeviceId",
                table: "UserDevices",
                column: "DeviceId");

            migrationBuilder.CreateIndex(
                name: "IX_UserDevices_UserId",
                table: "UserDevices",
                column: "UserId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "DeviceDataHistory");

            migrationBuilder.DropTable(
                name: "DeviceMonthDataHistories");

            migrationBuilder.DropTable(
                name: "UserDevices");

            migrationBuilder.DropTable(
                name: "Device");

            migrationBuilder.DropTable(
                name: "DeviceType");

            migrationBuilder.DropColumn(
                name: "TargetNotifiers",
                table: "AbpNotificationSubscriptions");
        }
    }
}
